package com.bj58.heatmap.util;

import java.util.List;

import com.bj58.dsap.api.scf.contract.IHbaseApi;
import com.bj58.dsap.api.scf.contract.Result;

public class HBaseTest {
	private static IHbaseApi hbase;
//	private static String tablename="ZhHomeHeatmapHBase";
	static {
//		String configPath = System.getProperty("user.dir")+ "/config/scf.config";
//		System.out.println(configPath);
//		SCFInit.init(configPath);
//		String url = "tcp://dsapapi/HbaseApi";
//		hbase = ProxyFactory.create(IHbaseApi.class, url);
		ScfUtil.initSCF();
		hbase=ScfUtil.getHbaseService();
	}
	
	
	public static void main(String[] args) {
		/**通过rowkey前缀查询 **/
		String prefix = "20150503_PC_bj_http://jing.58.com/adJump?adType=7&target=nTDQTHDKnTDQTHbkPTDOnjEKnTDQnHDQnHDQnEDksW0vPHcvrHEdrjD1rHNvnWcKnaYQsHDYn1TLn1nzPjbdrjTVnH9kPWTknH9vP9DdrTDzgvdbTgmQsWTK0v66UhIJpyDKmyQ_Ty6YIZTlszqBpB3draOWUvYfpvRhIitznjEvP1NzrHNzrjN3PM980v6YUyk4NDINiNEqnHEzPHbdnjbvPHb3rHT8PWNOP1TvPWnvPHmYrjTvniu6uA7WIjY1FbP_pyPoiNEqnE7_rRTzihuzXWuMpgGJHZGBrjbznWEdrHuhnAc1uywBmhnQn16bnANdnvm1rjbkPj0QPH76uynknHmQPAF-ujbOPvnOPADOnvNOrAubPH7bmE";
		int count = 0;
		List<Result> list = hbase.searchByPrefixFilter("ZhHomeHeatmapHBase", prefix);
		for(Result rs : list) {
			System.out.println(++count + ":" + rs.getScfMap().get("rowKey")+rs.getScfMap().get("cf:pv"));
		}
//		Result rs=hbase.queryByRowKey("ZhHomeHeatmapHBase", prefix+rowkey);
//		System.out.println(++count + ":" + rs.getScfMap().get("rowKey")+rs.getScfMap().get("cf:pv"));
		System.exit(0);
	}

	
	public void getByPrefix(String prefix){
		int count=0;
		List<Result> list=hbase.nextPagesByKeyPrefix("ZhHomeHeatmapHBase", prefix, "", 1000);
		while(list.size()==1000){
			count+=1000;
			String lastRowkey=(String) list.get(999).getScfMap().get("rowKey");
			System.out.println(lastRowkey);
			list=hbase.nextPagesByKeyPrefix("ZhHomeHeatmapHBase", prefix, lastRowkey, 1000);
			}
		System.out.println("共有"+count+"条记录！");
		System.out.println("\n------------------通过rowkey前缀查询 ---------------------");
	}
}
